//test2.cpp
#include<iostream>
#include<vector>
#include<string>
using namespace std;

int main()
{
    vector<string> text{"a","abc","abcde","abcdefg","abcdefghi"};
    string target_text = "abcdefg";

    for(auto i:text) cout<<i<<" ";
    cout<<endl<<"the target text is "<<target_text<<endl;

    auto begin = text.begin();
    auto end = text.end();
    auto middle = begin+(end-begin)/2;

    while(middle!=end && *middle!=target_text)
    {
        if(target_text<*middle)
            end=middle;
        else
            begin=middle+1;
        middle=begin+(end-begin)/2;
    }

    if(*middle==target_text)
    {
        cout<<"found the target text "<<target_text<<" at "<<middle+1-text.begin()<<endl;
    }
    getchar();
    return 0;
}